package com.ithaipeng.user.controller;

import com.ithaipeng.user.config.PatternProperties;
import com.ithaipeng.user.pojo.User;
import com.ithaipeng.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
@RequestMapping("/user")
/*@RefreshScope*/
public class UserController {
    @Autowired
    private UserService userService;
   /* @Value("${pattern.dateformat}")
    private String dateformat;*/
    @Autowired
    private PatternProperties patternProperties;
    @GetMapping("now")
    public String now(){
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(patternProperties.getDateformat()));
    }
    @GetMapping("/{userid}")
    public User findById(@PathVariable Long userid,
                         @RequestHeader(value = "Truth",required = false) String truth){
        System.err.println("truth:"+truth);
        return userService.findById(userid);
    }
    @GetMapping("prop")
    public PatternProperties prop(){
        return patternProperties;
    }
}
